<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户姓名" prop="custName">
        <el-input v-model="queryParams.custName" placeholder="请输入客户姓名" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="单件类型" prop="incomingType">
        <el-select v-model="queryParams.incomingType" placeholder="请选择单件类型" clearable>
          <el-option v-for="dict in dict.type.crm_singlePieceType" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="进件银行" prop="incomingBank">
        <el-select v-model="queryParams.incomingBank" placeholder="请选择进件银行" clearable>
          <el-option v-for="dict in dict.type.crm_incomingBank" :key="dict.value" :label="dict.label"
                     :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="进度" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择进度">
          <el-option v-for="dict in dict.type.crm_status" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>

      <el-form-item label="时间类型">
        <el-select v-model="queryParams.params.timeType" style="width: 30%; display: inline-block;" placeholder="条件"
                   clearable>
          <el-option label="进件时间" value="incomingDate"/>
          <el-option label="录入时间" value="createTime"/>
          <el-option label="确认时间" value="approveTime"/>
          <el-option label="收款时间" value="receiveDate"/>
        </el-select>
        <el-date-picker v-model="queryParams.params.timeContent" type="datetimerange" :picker-options="pickerOptions"
                        range-separator="至"
                        start-placeholder="开始日期" end-placeholder="结束日期" align="right" value-format="yyyy-MM-dd"
                        format="yyyy-MM-dd"
                        style="width: 70%;">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['incoming:incoming:add']">新增
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="incomingList" @selection-change="handleSelectionChange" fit
              style="width: 100%">
      <el-table-column type="selection" width="55" align="center" min-width="3%"/>
      <el-table-column label="进件日期" align="center" prop="incomingDate" min-width="3%"/>
      <el-table-column label="贷款顾问姓名" align="center" prop="empName" min-width="3%"/>
      <el-table-column label="部门归属名称" align="center" prop="orgName" min-width="3%"/>
      <el-table-column label="客户姓名" align="center" prop="custName" min-width="3%"/>
      <el-table-column label="付费方式" align="center" prop="payType" min-width="3%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.crm_pay_type" :value="scope.row.payType"/>
        </template>
      </el-table-column>
      <el-table-column label="进件银行" align="center" prop="incomingBank" min-width="3%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.crm_incomingBank" :value="scope.row.incomingBank"/>
        </template>
      </el-table-column>
      <el-table-column label="银行客户经理" align="center" prop="incomingAdviser" min-width="3%"/>
      <el-table-column label="费率/%" align="center" prop="incomingRate" min-width="3%"/>
      <el-table-column label="进件额度" align="center" prop="incomingAmount" min-width="3%"/>
      <el-table-column label="进度" align="center" prop="status" min-width="3%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.crm_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="批款额度" align="center" prop="approveAmount" min-width="3%"/>
      <el-table-column label="收款额" align="center" prop="receiveAmount" min-width="3%"/>
      <el-table-column label="收款日期" align="center" prop="receiveDate" min-width="3%"/>
      <el-table-column label="收款银行" align="center" prop="receiveBank" min-width="3%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.crm_incomingBank" :value="scope.row.receiveBank"/>
        </template>
      </el-table-column>
      <el-table-column label="成本费" align="center" prop="costAmount" min-width="3%"/>
      <el-table-column label="诚意金" align="center" prop="sincAmount" min-width="3%"/>
      <el-table-column label="录入时间" align="center" prop="createTime" min-width="3%"/>
      <el-table-column label="净创收" align="center" prop="createAmount" min-width="3%"/>
      <el-table-column label="单件类型" align="center" prop="incomingType" min-width="3%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.crm_singlePieceType" :value="scope.row.incomingType"/>
        </template>
      </el-table-column>
      <el-table-column label="确认人姓名" align="center" prop="approveEmpName" min-width="3%"/>
      <el-table-column label="确认时间" align="center" prop="approveTime" width="180" min-width="3%">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approveTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="left" width="280" prop="remark" min-width="3%">
        <template slot-scope="scope">
          <span v-html='scope.row.remark' class="span_remark"></span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" min-width="3%">
        <template slot-scope="scope">

          <dict-tag :options="dict.type.crm_status" :value="scope.row.status" v-if="scope.row.status!=1"/>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-if="scope.row.status==1">编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 添加或修改我的审件对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>

    </el-dialog>
  </div>
</template>

<script>
import {listIncoming, getIncoming, delIncoming, addIncoming, updateIncoming} from "@/api/incoming/incoming";

export default {
  name: "Incoming",
  dicts: ['crm_pay_type', 'crm_incomingBank', 'crm_status', 'crm_singlePieceType'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 我的审件表格数据
      incomingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        custName: null,
        incomingType: null,
        incomingBank: null,
        orgId: null,
        status: "1",
        params: {
          timeType: null,
          timeContent: null
        }
      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    /** 查询我的审件列表 */
    getList() {
      this.loading = true;
      listIncoming(this.queryParams).then(response => {
        this.incomingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      const params = {id: '', pageNum: this.queryParams.pageNum, form: this.form, routePath: this.$route.path};
      this.$tab.openPage(
        "添加我的审件",
        "/crmsys/incomingdit/info/",
        params
      );
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids;
      const params = {id: id, pageNum: this.queryParams.pageNum, form: this.form, routePath: this.$route.path};
      this.$tab.openPage(
        "修改我的审件",
        "/crmsys/incomingdit/info/",
        params
      );
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除我的审件编号为"' + ids + '"的数据项？').then(function () {
        return delIncoming(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('incoming/incoming/export', {
        ...this.queryParams
      }, `incoming_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style lang="scss" scoped>
@import '@/assets/styles/command.scss';
</style>
